﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using UIControls.Core;
namespace UIControls
{
    public class CsDateTimePicker : LabelCell, IUIControl
    {
        public DateTimePicker DateTimePicker;
        
        public CsDateTimePicker()
        {
            InitializeComponent();
            DateTimePicker.Format = DateTimePickerFormat.Custom;
            DateTimePicker.CustomFormat = "yyyy-MM-dd";
        }
        protected override Size DefaultSize
        {
            get
            {
                return new Size(250, 30);
            }
        }
        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            base.SetBoundsCore(x, y, width, DefaultSize.Height, specified);
        }


        public string LabelText
        {
            get
            {
                return base.Text;
            }
            set
            {
                base.Text = value;
            }
        }

        private int _LabelWidth=100;
        public int LabelWidth
        {
            get { return _LabelWidth; }
            set
            {
                _LabelWidth = value;
            }
        }
        protected override void OnLayout(LayoutEventArgs levent)
        {
            DateTimePicker.Location = new Point(this.LabelWidth, 5);

            DateTimePicker.Width = this.Width - this.LabelWidth;
        }

        protected override void OnPaint(PaintEventArgs e)
        {

            e.Graphics.DrawString(this.LabelText, this.Font, new SolidBrush(GlobalUIVar.gLabelColor), new Point(e.ClipRectangle.Left + 5, e.ClipRectangle.Top + 10));
        }

        private void InitializeComponent()
        {
            this.DateTimePicker = new System.Windows.Forms.DateTimePicker();
            this.Controls.Add(this.DateTimePicker);
            this.SuspendLayout();
            // 
            // DateTimePicker
            // 
            this.DateTimePicker.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.DateTimePicker.Location = new System.Drawing.Point(0, 5);
            this.DateTimePicker.Name = "DateTimePicker";
            this.DateTimePicker.Size = new System.Drawing.Size(200, 20);
            this.DateTimePicker.TabIndex = 0;
            this.ResumeLayout(false);

        }
    }

}
